import classnames from 'classnames'

import Icon from '@/components/Icon'

import styles from './index.module.scss'
import { Article } from '@/types/data'
import dayjs from 'dayjs'
// dayjs相对时间插件 不需要下载 需要你启用
import relativeTime from 'dayjs/plugin/relativeTime'

// 需要中文 启用中文包
import 'dayjs/locale/zh-cn'
import Image from '@/components/Image'
dayjs.locale('zh-cn')

dayjs.extend(relativeTime)

type Props = {
  /**
   * 0 表示无图
   * 1 表示单图
   * 3 表示三图
   */
  type?: 0 | 1 | 3
  article: Article
}

const ArticleItem = ({ type = 0, article }: Props) => {
  return (
    <div className={styles.root}>
      <div
        className={classnames(
          'article-content',
          type === 3 && 't3',
          type === 0 && 'none-mt'
        )}
      >
        <h3>{article.title}</h3>
        {type !== 0 && (
          <div className="article-imgs">
            {article.cover.images!.map((item, index) => {
              return (
                <div className="article-img-wrapper" key={index}>
                  {/* <img src={item} alt="" /> */}
                  <Image src={item}></Image>
                </div>
              )
            })}
          </div>
        )}
      </div>
      <div className={classnames('article-info', type === 0 && 'none-mt')}>
        <span>{article.aut_name}</span>
        <span>{article.comm_count} 评论</span>
        <span>{dayjs(article.pubdate).fromNow()}</span>
        <span className="close">
          <Icon name="iconbtn_essay_close" />
        </span>
      </div>
    </div>
  )
}

export default ArticleItem
